#pragma once

#include "EasyBMP.h"

namespace rt
{
	struct RT_Pixel
	{
		byte R, G, B, A;
	};

	class RT_BMP
	{
	private:
		BMP _bmp;

		int _width;
		int _height;

	public:
		RT_BMP(int width, int height) :
			_width(width), _height(height)
		{
			_bmp.SetSize(width, height);
		}

		void WriteToFile(const char * filename)
		{
			_bmp.WriteToFile(filename);
		}

		// ##### interface necessary for class to be used as a rendertarget in Tracer class
		__forceinline void SetPixel(int x, int y, RT_Pixel pixel)
		{
			RGBApixel p;
			p.Red = pixel.R;
			p.Green = pixel.G;
			p.Blue = pixel.B;
			p.Alpha = pixel.A;
			_bmp.SetPixel(x, y, p);
		}

		int GetWidth()
		{
			return _width;
		}
		int GetHeight()
		{
			return _height;
		}

		// #####
	};

	class RT_Memory
	{
	private:
		RT_Pixel (* _pixels);
		int _width;
		int _height;

	public:
		RT_Memory(int width, int height) :
			_width(width), _height(height)
		{
			_pixels = new RT_Pixel[width * height];
		}

		~RT_Memory()
		{
			delete _pixels;
		}

		RT_Pixel * GetPixels()
		{
			return _pixels;
		}

		// ##### interface necessary for class to be used as a rendertarget in Tracer class
		void SetPixel(int x, int y, RT_Pixel pixel)
		{
			int start = (_height - y - 1) * _width + x;
			_pixels[start].R = pixel.R;
			_pixels[start].G = pixel.G;
			_pixels[start].B = pixel.B;
			_pixels[start].A = pixel.A;
		}

		int GetWidth()
		{
			return _width;
		}
		int GetHeight()
		{
			return _height;
		}

		// #####
	};

}
